package cn.sms.pay.service.impl;

import cn.sms.basic.exception.BusinessException;
import cn.sms.basic.service.impl.BaseServiceImpl;
import cn.sms.order.service.IProductOrderService;
import cn.sms.pay.domain.AlipayInfo;
import cn.sms.pay.domain.PayBill;
import cn.sms.pay.mapper.AlipayInfoMapper;
import cn.sms.pay.mapper.PayBillMapper;
import cn.sms.pay.service.IPayBillService;
import cn.sms.pay.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Autowired
    private AlipayInfoMapper alipayInfoMapper;

    @Autowired
    private PayBillMapper payBillMapper;

    @Autowired
    private IProductOrderService productOrderService;

    @Override
    public String pay(PayBill payBill) {
        if(payBill.getId() == null || payBill == null){
            throw new BusinessException("你个扑该");
        }
        PayBill bill = payBillMapper.loadById(payBill.getId());
        if(bill == null){
            throw new BusinessException("你个扑该");
        }
        switch (bill.getPayChannel().intValue()){
            case 1:{
                AlipayInfo alipayInfo = alipayInfoMapper.loadByShopId(bill.getShop_id());
                return AlipayUtils.pay(bill, alipayInfo);
            }
            case 2:{

            }
            case 3:{

            }
            default:break;
        }
        return null;
    }

    @Override
    public PayBill loadByUnionPaySn(String out_trade_no1) {
        return payBillMapper.loadByUnionPaySn(out_trade_no1);
    }
}
